package com.ruoyi.business.tool;

import com.ruoyi.business.mapper.AcCustomerInfoMapper;
import com.ruoyi.business.service.impl.AcCustomerInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.Random;

@Service
@Component
public class CustomerInfoTool {

    @Autowired
    private AcCustomerInfoMapper acCustomerInfoMapper;

    @Autowired
    private AcCustomerInfoServiceImpl acCustomerInfoService;
    /**
     * 随机生成6位正整数
     *
     * **/
    public Long generateRandomNumber() {
        Random random = new Random();
        Long result = 0L;
        while (true) {
            result = 100000L + random.nextInt(900000);  // 生成 100000 - 999999 之间的随机数
            int count = acCustomerInfoMapper.matchCustomerInfoByCustomerCode(result.toString());
            if(0 == count) {
                break;
            }
        }
        return result;
    }

    /**
     * 客户状态定时器
     * 判断该客户租赁信息中，租赁状态是否有在租
     * 若该客户没有在租信息，则将该客户租赁状态改为1：未租
     * **/
//    @Scheduled(cron = "0 0 0 * * ?")  // 每天00：00：00执行
//    @Scheduled(cron = "0/10 * * * * ?")  // 每10秒执行
    public void updateAcCustomerInfoByLeaseStatus() {
        acCustomerInfoService.updateAcCustomerInfoByLeaseStatus();
    }
}
